home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgfx10.zip / EMSDEMO2.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-01  |  8KB  |  291 lines

  1. { EMS unit demo program - (C) Copyright 1994 Brian Manning
  2.  
  3.   What makes this demo different from EMSDEMO.PAS is that I am only
  4.   allocating 1 page of EMS memory for all three balls!  I wanted to
  5.   include this demo as an example of using EMS pages more efficiently.
  6.  
  7.   In EMSDEMO.PAS I allocated a page for each sprite, since each sprite
  8.   I'm using here never exceeds 891 bytes; why allocate almost 50k of EMS
  9.   for them?  So this demo only allocates the one 16k page in EMS for all
  10.   three ball sprites, happy coding!
  11.  
  12. }
  13. {$I-,D-,S+,X+}
  14.  
  15. program EMS_Demo;
  16.  
  17. uses dos,crt,vgfx,ems;
  18.  
  19. { Declare our variables }
  20. var emsver : word;
  21.     bytes  : longint;
  22.     pages,
  23.     i,
  24.     handle : integer;
  25.     x, y   : array[1..25] of integer;
  26.     hit    : array[1..25] of byte;
  27.     hitY   : array[1..25] of byte;
  28.     m      : byte;
  29.  
  30.  
  31. { Main Procedure! }
  32. begin
  33.      clrscr;
  34.      writeln;
  35.  
  36.      { Initialize the EMS driver }
  37.      EMSVer := EMS_Init;
  38.  
  39.      if (EMSResult >= $80) then
  40.      begin
  41.           { There was an EMS error, so display the description }
  42.           writeln('EMS Error:  ', EMS_ErrDesc[EMSResult]);
  43.           halt(1);
  44.      end
  45.      else if (EMSVer <> 0) then
  46.          writeln('EMS version: ', (EMSVer div 10), '.', (EMSVer mod 10))
  47.      else
  48.      begin
  49.           writeln('EMS Demo:  No EMS driver found!');
  50.           halt(1);
  51.      end;
  52.  
  53.  
  54.      { Get the amount of free pages of EMS memory }
  55.      pages:=EMSFreePages;
  56.  
  57.      { Display the EMS memory status on the screen }
  58.      writeln(pages, ' pages available (', (longint(16384)*pages) div 1024,
  59.                     'k of total storage)');
  60.  
  61.  
  62.      { Allocate 1 page of EMS memory (16384 bytes) }
  63.      handle:=EMSAlloc(1);
  64.  
  65.      if (EMSResult>=$80) then
  66.      begin
  67.           { There was an EMS error, so display the description }
  68.           writeln('EMS Alloc Error:  ', EMS_ErrDesc[EMSResult]);
  69.           halt(1);
  70.      end;
  71.  
  72.  
  73.      { Map this page so we can use it }
  74.      if not(EMSMap(Handle, 0, 0)) then
  75.      begin
  76.           { There was an EMS error, so display the description }
  77.           writeln('EMS Map Error:  ', EMS_ErrDesc[EMSResult],i);
  78.           EMSFree(handle);
  79.           halt(1);
  80.      end;
  81.  
  82.  
  83.      writeln;
  84.      writeln('1 page of EMS memory allocated and ready!');
  85.      writeln;
  86.      write('Press any key to begin ...');
  87.      readkey;
  88.  
  89.  
  90.      { Initialize VGFX }
  91.      VGFX_Init;
  92.  
  93.      { Tell VGFX to use DEMO.GFX for all it's file handling }
  94.      SetWorkLib('demo.gfx');
  95.  
  96.  
  97.      { Set our work page to 4 (so the user cannot see the image loaded) }
  98.      SetWorkPage(4);
  99.  
  100.      { Load up our images }
  101.      ShowPcx ('balls.pcx', 0, 4);
  102.  
  103.      { Get images into EMS memory }
  104.  
  105.      { Set the offset of the page to 0 (begining) }
  106.      EMSPageOfs(0);
  107.      GetImage (EMSPage(0)^, 10, 7, 15, 13);
  108.  
  109.      { Set the offset of the page to 196 (end of 1st ball) }
  110.      EMSPageOfs(196);
  111.      GetImage (EMSPage(0)^, 45, 7, 25, 21);
  112.  
  113.      { Set the offset of the page to 721 (end of 2nd ball) }
  114.      EMSPageOfs(721);
  115.      GetImage (EMSPage(0)^, 96, 7, 33, 27);
  116.  
  117.      { Clear the screen }
  118.      clearscreen(0);
  119.  
  120.      { Set our work page to 1 }
  121.      SetWorkPage(1);
  122.  
  123.      { Show the PCX on page 3 (the background page) }
  124.      ShowPcx('frac.pcx',0,3);
  125.  
  126.      randomize;
  127.      for i := 1 to 25 do
  128.      begin
  129.           x[i]   := random(300);
  130.           y[i]   := random(175);
  131.           hit[i] := random(2);
  132.           hitY[i]:= random(2);
  133.      end;  { end for\do }
  134.  
  135.      repeat
  136.            { All of the FOR/DO loops from here on are checking the ball's
  137.              boundaries and moving them accordingly }
  138.  
  139.            for m := 1 to 5 do
  140.            begin
  141.                 if (x[m] > 274) then hit[m] := 0;
  142.                 if (x[m] < 1)   then hit[m] := 1;
  143.                 if (y[m] > 186) then hitY[m]:= 0;
  144.                 if (y[m] < 1)   then hitY[m]:= 1;
  145.  
  146.                 Case hit[m] of
  147.                      1 : inc(x[m],2);
  148.                      0 : dec(x[m],2);
  149.                 end; { end case }
  150.  
  151.                 Case hitY[m] of
  152.                      1 : inc(y[m],2);
  153.                      0 : dec(y[m],2);
  154.                 end; { end case }
  155.            end;  { end for\do }
  156.  
  157.            for m := 6 to 10 do
  158.            begin
  159.                 if (x[m] > 274) then hit[m] := 0;
  160.                 if (x[m] < 1)   then hit[m] := 1;
  161.                 if (y[m] > 186) then hitY[m]:= 0;
  162.                 if (y[m] < 1)   then hitY[m]:= 1;
  163.  
  164.                 Case hit[m] of
  165.                      1 : inc(x[m],1);
  166.                      0 : dec(x[m],1);
  167.                 end; { end case }
  168.  
  169.                 Case hitY[m] of
  170.                      1 : inc(y[m],1);
  171.                      0 : dec(y[m],1);
  172.                 end; { end case }
  173.            end;  { end for\do }
  174.  
  175.            for m := 11 to 14 do
  176.            begin
  177.                 if (x[m] > 294) then hit[m] := 0;
  178.                 if (x[m] < 1)   then hit[m] := 1;
  179.                 if (y[m] > 179) then hitY[m]:= 0;
  180.                 if (y[m] < 1)   then hitY[m]:= 1;
  181.  
  182.                 Case hit[m] of
  183.                      1 : inc(x[m],1);
  184.                      0 : dec(x[m],1);
  185.                 end; { end case }
  186.  
  187.                 Case hitY[m] of
  188.                      1 : inc(y[m],1);
  189.                      0 : dec(y[m],1);
  190.                 end; { end case }
  191.            end;  { end for\do }
  192.  
  193.            for m := 15 to 18 do
  194.            begin
  195.                 if (x[m] > 294) then hit[m] := 0;
  196.                 if (x[m] < 1)   then hit[m] := 1;
  197.                 if (y[m] > 179) then hitY[m]:= 0;
  198.                 if (y[m] < 1)   then hitY[m]:= 1;
  199.  
  200.                 Case hit[m] of
  201.                      1 : inc(x[m],2);
  202.                      0 : dec(x[m],2);
  203.                 end; { end case }
  204.  
  205.                 Case hitY[m] of
  206.                      1 : inc(y[m],2);
  207.                      0 : dec(y[m],2);
  208.                 end; { end case }
  209.            end;  { end for\do }
  210.  
  211.            for m := 19 to 21 do
  212.            begin
  213.                 if (x[m] > 294) then hit[m] := 0;
  214.                 if (x[m] < 1)   then hit[m] := 1;
  215.                 if (y[m] > 179) then hitY[m]:= 0;
  216.                 if (y[m] < 1)   then hitY[m]:= 1;
  217.  
  218.                 Case hit[m] of
  219.                      1 : inc(x[m],4);
  220.                      0 : dec(x[m],4);
  221.                 end; { end case }
  222.  
  223.                 Case hitY[m] of
  224.                      1 : inc(y[m],4);
  225.                      0 : dec(y[m],4);
  226.                 end; { end case }
  227.            end;  { end for\do }
  228.  
  229.            for m := 22 to 25 do
  230.            begin
  231.                 if (x[m] > 286) then hit[m] := 0;
  232.                 if (x[m] < 1)   then hit[m] := 1;
  233.                 if (y[m] > 172) then hitY[m]:= 0;
  234.                 if (y[m] < 1)   then hitY[m]:= 1;
  235.  
  236.                 Case hit[m] of
  237.                      1 : inc(x[m],3);
  238.                      0 : dec(x[m],3);
  239.                 end; { end case }
  240.  
  241.                 Case hitY[m] of
  242.                      1 : inc(y[m],3);
  243.                      0 : dec(y[m],3);
  244.                 end; { end case }
  245.            end;  { end for\do }
  246.  
  247.            { Put the images on the screen! }
  248.  
  249.            { Set the offset of the page to 0 (start of 1st ball) }
  250.            EMSPageOfs(0);
  251.            for m:=1 to 10 do
  252.                PutClip(EMSPage(0)^, x[m], y[m], 15, 13);
  253.  
  254.            { Set the offset of the page to 196 (start of 2nd ball) }
  255.            EMSPageOfs(196);
  256.            for m:=11 to 21 do
  257.                PutClip(EMSPage(0)^, x[m], y[m], 25, 21);
  258.  
  259.            { Set the offset of the page to 721 (start of 3rd ball) }
  260.            EMSPageOfs(721);
  261.            for m:=22 to 25 do
  262.                PutClip(EMSPage(0)^, x[m], y[m], 33, 27);
  263.  
  264.            { Now update the screen with all of our new stuff }
  265.            Update;
  266.  
  267.      until keypressed;
  268.  
  269.      readkey;
  270.  
  271.      { Cleanup our mess and set the video mode back to text! }
  272.      VGFX_Done;
  273.  
  274.      { Free the EMS memory we allocated earlier }
  275.      EMSFree(handle);
  276.  
  277.      { Check for EMS error }
  278.      if (EMSResult>=$80) then
  279.      begin
  280.           { There was an EMS error, so display the description }
  281.           writeln('EMS Free Error:  ', EMS_ErrDesc[EMSResult]);
  282.           halt(1);
  283.      end
  284.      else
  285.          writeln('EMS memory freed, demo completed successfully.');
  286.  
  287.      writeln;
  288.      halt(0);
  289.  
  290. end.
  291.